<template>
  <div>
  <router-link :to="{ path:'seller-admin-edit', query:{seller_id:this.$route.query.id}}" class="el-button" style="float:right;margin:10px 0px">添加{{name}}管理员</router-link>
  <el-table
    :data="tableData"
	border
    style="width: 100%; margin: 10px 10px">
    <el-table-column
      prop="username"
      label="用户名">
    </el-table-column>
	<el-table-column
      prop="dateline"
      label="创建时间">
    </el-table-column>
	<el-table-column label="操作" width="255">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
	
  </el-table>
  <el-pagination
	  background
	  layout="prev, pager, next"
	  :page-size="pagesize"
	  @current-change="currentPage"
	  :total="total">
	</el-pagination>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [],
		pagesize : 10,
		total: 10,
		page: 1,
		name: '',
      }
    },
    methods: {
	  getSellerAdminList(currentPage){
		this.$axios({
			method:"post",
			url:this.host+"/admin/index.php/Seller/getSellerAdminList",
			data:{
				page: currentPage?parseInt(currentPage):this.page,
				pagesize: this.pagesize,
				seller_id: this.$route.query.id,
			}
		}).then((res)=>{
			this.loading = false  
			console.log(res)
			this.tableData = res.data.list
			this.total = res.data.total
		})
	  },
	  getSeller(){
		this.$axios({
			method:"post",
			url:this.host+"/admin/index.php/Seller/getSeller",
			data:{
				id : this.$route.query.id,
			}
		}).then((res)=>{
			this.name = res.data.name
		})
	  },
	  currentPage(val){
		this.getSellerList(val)
	  },
	  handleEdit(index, row){
		this.$router.push({ path: 'seller-admin-edit', query:{id:row.id}})
	  },
	  handleDelete(index, row){
		this.$axios({
			method:"post",
			url:this.host+"/admin/index.php/Seller/delSellerAdmin",
			data:{
				id: row.id,
			}
		}).then((res)=>{
			this.$message({
				  message: '删除成功',
				  type: 'success'
				});
			this.tableData.splice(index, 1);
		})
	  }
    },
    mounted: function mounted() {
        this.getSellerAdminList();
		this.getSeller();
    }
  }
</script>
